import json

from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
from django.utils.decorators import method_decorator
from django.views import View

def my_decorator(func):
    def wrapper(request, *args, **kwargs):
        print('自定义装饰器被调用了')
        print('请求路径%s' % request.path)
        return func(request, *args, **kwargs)
    return wrapper

def student(request):
    if request.method == 'GET':
        return HttpResponse('收到get请求')
    elif request.method == 'POST':
        print('post')
        return HttpResponse('收到post请求')
    elif request.method == 'PUT':
        print('put')
        return HttpResponse('收到PU请求')
    elif request.method == 'DELETE':
        print('delete')
        return HttpResponse('收到delete请求')

@method_decorator(my_decorator,name='get')
class StudentView(View):
    def get(self, request):
        return HttpResponse('收到get请求')

    def post(self, request):
        return HttpResponse('收到post请求')
